package com.music.muisc.dao;

import com.music.muisc.dto.MusicQuantity;
import com.music.muisc.entity.Music;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface MusicRepository extends CrudRepository<Music, Integer> {

@Override
List<Music> findAll();//编写覆盖方法,编写自定义的findAll方法，让其返回列表
    @Query(nativeQuery = true, value = "SELECT name as label, COUNT(*) as value FROM music GROUP BY name")
    List<MusicQuantity> musicQuantities();
}//继承CrudRepository以使用常规的CRUD方法，并指明数据实体的类名和数据实体中的ID字段的类型
